//
//  TestClassB.m
//  MessageForwarding
//
//  Created by 刘博 on 15/4/25.
//  Copyright (c) 2015年 AutoNavi. All rights reserved.
//

#import "TestClassB.h"
#import "TestClassA.h"
#import <objc/runtime.h>

@interface TestClassB ()
{
    TestClassA *_internalClassA;
}

@end

@implementation TestClassB

- (instancetype)init
{
    if (self = [super init])
    {
        _internalClassA = [[TestClassA alloc] init];
    }
    return self;
}

#pragma mark - Step 1: resolveMethod

+ (BOOL)resolveInstanceMethod:(SEL)sel
{
    NSLog(@"%s", __func__);
    
    return [super resolveInstanceMethod:sel];
}

+ (BOOL)resolveClassMethod:(SEL)sel
{
    NSLog(@"%s", __func__);
    
    return [super resolveClassMethod:sel];
}

#pragma mark - Step 2: forwardingTargetForSelector

- (id)forwardingTargetForSelector:(SEL)aSelector
{
    NSLog(@"%s", __func__);
    
    if (aSelector == @selector(doDynamicAddMethod))
    {
        return _internalClassA;
    }
    
    return [super forwardingTargetForSelector:aSelector];
}

#pragma mark - Step 3: forwardInvocation

- (BOOL)respondsToSelector:(SEL)aSelector
{
    NSLog(@"%s", __func__);
    
    return [super respondsToSelector:aSelector];
}

+ (BOOL)instancesRespondToSelector:(SEL)aSelector
{
    NSLog(@"%s", __func__);
    
    return [super instancesRespondToSelector:aSelector];
}

- (NSString *)aIMPForForwardInvocation
{
    NSLog(@"%s", __func__);
    
    return @"ClassB aIMPForForwardInvocation";
}

@end
